package com.jinkaimen.kqb.ui.activity.h5toapp;

import android.Manifest;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Message;
import android.provider.MediaStore;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.FileProvider;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.ht.baselibs.bean.BaseGetBean;
import com.ht.baselibs.retrofit.NetCallBack;
import com.ht.baselibs.retrofit.RequestUtils;
import com.ht.baselibs.retrofit.bean.RequestParam;
import com.ht.baselibs.retrofit.converter.fastjson.FastJsonConverterFactory;
import com.ht.baselibs.ui.base.BaseActivity;
import com.ht.baselibs.ui.widget.TitleBarView;
import com.ht.baselibs.utils.ActivityUtils;
import com.ht.baselibs.utils.DateUtils;
import com.ht.baselibs.utils.DeviceUtils;
import com.ht.baselibs.utils.LogUtils;
import com.ht.baselibs.utils.SharedPreferencesUtils;
import com.ht.baselibs.utils.UIUtils;
import com.jinkaimen.kqb.R;
import com.jinkaimen.kqb.api.FileApi;
import com.jinkaimen.kqb.bean.AuStepBean;
import com.jinkaimen.kqb.constant.HttpConfig;
import com.jinkaimen.kqb.http.ConsultInterceptor;
import com.jinkaimen.kqb.manager.ApiManager;
import com.jinkaimen.kqb.thread.CompressPhotoThread;
import com.jinkaimen.kqb.ui.weiget.CustomPopwindow;
import com.jinkaimen.kqb.ui.weiget.DialogUtils;
import com.jinkaimen.kqb.utils.PermissionUtils;


import java.io.File;
import java.util.HashMap;
import java.util.Map;

import okhttp3.OkHttpClient;
import okhttp3.RequestBody;
import retrofit2.Call;
import retrofit2.Response;
import retrofit2.Retrofit;

public class UpdatePicActivity extends BaseActivity {

    private static final int REQUEST_CODE_TAKE_PHOTO_DOOR = 0;
    private static final int REQUEST_CODE_TAKE_PHOTO_DOOR_PHOTO = 3;
    private static final int REQUEST_CODE_TAKE_PHOTO_COUNTER = 1;
    private static final int REQUEST_CODE_TAKE_PHOTO_COUNTER_PHOTO = 4;
    private static final int REQUEST_CODE_TAKE_PHOTO_INDOOR = 2;
    private static final int REQUEST_CODE_TAKE_PHOTO_INDOOR_PHOTO = 5;
    private static final int REQUEST_CODE_TAKE_PHOTO_BANKCARD = 6;
    private static final int REQUEST_CODE_TAKE_PHOTO_BANKCARD_PHOTO = 7;

    private static final int MY_PERMISSIONS_REQUEST_CALL_CAMERA = 0;
    private static final int MY_PERMISSIONS_REQUEST_CALL_WRITE_SDCARD = 1;

    private static String TAKE_PHOTO_PATH_DOOR = "ht/jkm/photo/STOREFRONT.jpg";
    private static String TAKE_PHOTO_PATH_COUNTER = "ht/jkm/photo/COUNTER.jpg";
    private static String TAKE_PHOTO_PATH_INDOOR = "ht/jkm/photo/INDOOR.jpg";
    private static String TAKE_PHOTO_PATH_BANKCARD = "ht/jkm/photo/bankcard.jpg";

    private TextView mStep1View;
    private TextView mStep2View;
    private TextView mStep3View;

    private ImageView mDoorView;
    private ImageView mCounterView;
    private ImageView mIndoorView;
    private ImageView mBankCardView;
    private boolean hasDoorImage;
    private boolean hasCounterImage;
    private boolean hasIndoorImage;
    private long mShopId;
    private long mUserId;
    private TextView mNextButton;
    private boolean mIsPublic;
    private boolean canEdit;
    private String picturePath3;
    private String picturePath2;
    private String picturePath1;
    private String picturePath;
    private Uri imageUri;
    private String url1;
    private String url2;
    private String url3;
    private String url4;

    @Override
    protected boolean isStaticPage() {
        return true;
    }

    @Override
    protected void initTitleBar() {
        mTitleBarView.setTitleText("填写店铺资料");
    }

    @Override
    protected int initContentView() {
        return R.layout.activity_update_pic;
    }

    @Override
    protected void initChildView() {
        mStep1View = (TextView) findViewById(R.id.tv_header_identification_step1);
        mStep2View = (TextView) findViewById(R.id.tv_header_identification_step2);
        mStep3View = (TextView) findViewById(R.id.tv_header_identification_step3);

        mDoorView = (ImageView) findViewById(R.id.iv_activity_identification_shop_step2_door);
        mCounterView = (ImageView) findViewById(R.id.iv_activity_identification_shop_step2_counter);
        mIndoorView = (ImageView) findViewById(R.id.iv_activity_identification_shop_step2_indoor);
        mBankCardView = (ImageView) findViewById(R.id.iv_activity_identification_shop_step2_bankcard);
        mNextButton = (TextView) findViewById(R.id.btn_activity_identification_shop);

        Drawable drawable = getResources().getDrawable(R.mipmap.identification_step1_end);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        mStep1View.setCompoundDrawables(drawable, null, null, null);
        mStep2View.setEnabled(true);

    }

    @Override
    protected void initChildData() {

    }

    @Override
    protected void setChildViewListener() {
        mNextButton.setClickable(true);
        mNextButton.setOnClickListener(this);
        mDoorView.setOnClickListener(this);
        mCounterView.setOnClickListener(this);
        mIndoorView.setOnClickListener(this);
        mBankCardView.setOnClickListener(this);
    }

    private void takePicture(int requestCode) {
        String path = null;
        switch (requestCode) {
            case 0:
                DialogUtils.createPopwindow(UpdatePicActivity.this, "", "取消", new CustomPopwindow.OnBtnClickListener("拍照") {
                    @Override
                    public void onClick(CustomPopwindow popwindow, View view) {
                        try {

                            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                            File file = new File(Environment.getExternalStorageDirectory(), TAKE_PHOTO_PATH_DOOR);

                            if (!file.getParentFile().exists()) {
                                file.getParentFile().mkdirs();
                            }
//                            intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
//                            startActivityForResult(intent, REQUEST_CODE_TAKE_PHOTO_DOOR);

                            imageUri = FileProvider.getUriForFile(UpdatePicActivity.this, "com.jinkaimen.kqb.fileprovider", file);
                            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); //添加这一句表示对目标应用临时授权该Uri所代表的文件
                            intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);//设置Action为拍照
                            intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);//将拍取的照片保存到指定URI
                            startActivityForResult(intent, REQUEST_CODE_TAKE_PHOTO_DOOR);

                        } catch (Exception e) {
                            UIUtils.showToast("无法启用系统相机");
                            e.printStackTrace();
                        }

                    }
                }, new CustomPopwindow.OnBtnClickListener("从相册选择") {
                    @Override
                    public void onClick(CustomPopwindow popwindow, View view) {

                        Intent i = new Intent(
                                Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                        startActivityForResult(i, REQUEST_CODE_TAKE_PHOTO_DOOR_PHOTO);
                    }
                }).showAtBottom(mTitleBarView);
                break;
            case 1:
                DialogUtils.createPopwindow(UpdatePicActivity.this, "", "取消", new CustomPopwindow.OnBtnClickListener("拍照") {
                    @Override
                    public void onClick(CustomPopwindow popwindow, View view) {
                        try {

                            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                            File file = new File(Environment.getExternalStorageDirectory(), TAKE_PHOTO_PATH_COUNTER);

                            if (!file.getParentFile().exists()) {
                                file.getParentFile().mkdirs();
                            }
//                            intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
//                            startActivityForResult(intent, REQUEST_CODE_TAKE_PHOTO_COUNTER);
                            imageUri = FileProvider.getUriForFile(UpdatePicActivity.this, "com.jinkaimen.kqb.fileprovider", file);
                            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); //添加这一句表示对目标应用临时授权该Uri所代表的文件
                            intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);//设置Action为拍照
                            intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);//将拍取的照片保存到指定URI
                            startActivityForResult(intent, REQUEST_CODE_TAKE_PHOTO_COUNTER);

                        } catch (Exception e) {
                            UIUtils.showToast("无法启用系统相机");
                            e.printStackTrace();
                        }

                    }
                }, new CustomPopwindow.OnBtnClickListener("从相册选择") {
                    @Override
                    public void onClick(CustomPopwindow popwindow, View view) {

                        Intent i = new Intent(
                                Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                        startActivityForResult(i, REQUEST_CODE_TAKE_PHOTO_COUNTER_PHOTO);
                    }
                }).showAtBottom(mTitleBarView);
                break;
            case 2:
                DialogUtils.createPopwindow(UpdatePicActivity.this, "", "取消", new CustomPopwindow.OnBtnClickListener("拍照") {
                    @Override
                    public void onClick(CustomPopwindow popwindow, View view) {
                        try {

                            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                            File file = new File(Environment.getExternalStorageDirectory(), TAKE_PHOTO_PATH_INDOOR);

                            if (!file.getParentFile().exists()) {
                                file.getParentFile().mkdirs();
                            }
//                            intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
//                            startActivityForResult(intent, REQUEST_CODE_TAKE_PHOTO_INDOOR);

                            imageUri = FileProvider.getUriForFile(UpdatePicActivity.this, "com.jinkaimen.kqb.fileprovider", file);
                            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); //添加这一句表示对目标应用临时授权该Uri所代表的文件
                            intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);//设置Action为拍照
                            intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);//将拍取的照片保存到指定URI
                            startActivityForResult(intent, REQUEST_CODE_TAKE_PHOTO_INDOOR);

                        } catch (Exception e) {
                            UIUtils.showToast("无法启用系统相机");
                            e.printStackTrace();
                        }

                    }
                }, new CustomPopwindow.OnBtnClickListener("从相册选择") {
                    @Override
                    public void onClick(CustomPopwindow popwindow, View view) {

                        Intent i = new Intent(
                                Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                        startActivityForResult(i, REQUEST_CODE_TAKE_PHOTO_INDOOR_PHOTO);
                    }
                }).showAtBottom(mTitleBarView);
                break;
            case 3:
                DialogUtils.createPopwindow(UpdatePicActivity.this, "", "取消", new CustomPopwindow.OnBtnClickListener("拍照") {
                    @Override
                    public void onClick(CustomPopwindow popwindow, View view) {
                        try {

                            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                            File file = new File(Environment.getExternalStorageDirectory(), TAKE_PHOTO_PATH_BANKCARD);

                            if (!file.getParentFile().exists()) {
                                file.getParentFile().mkdirs();
                            }
//                            intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
//                            startActivityForResult(intent, REQUEST_CODE_TAKE_PHOTO_INDOOR);

                            imageUri = FileProvider.getUriForFile(UpdatePicActivity.this, "com.jinkaimen.kqb.fileprovider", file);
                            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); //添加这一句表示对目标应用临时授权该Uri所代表的文件
                            intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);//设置Action为拍照
                            intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);//将拍取的照片保存到指定URI
                            startActivityForResult(intent, REQUEST_CODE_TAKE_PHOTO_BANKCARD);


                        } catch (Exception e) {
                            UIUtils.showToast("无法启用系统相机");
                            e.printStackTrace();
                        }

                    }
                }, new CustomPopwindow.OnBtnClickListener("从相册选择") {
                    @Override
                    public void onClick(CustomPopwindow popwindow, View view) {

                        Intent i = new Intent(
                                Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                        startActivityForResult(i, REQUEST_CODE_TAKE_PHOTO_BANKCARD_PHOTO);
                    }
                }).showAtBottom(mTitleBarView);
                break;
        }

//        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
//        File file = new File(Environment.getExternalStorageDirectory(), path);
//
//        if (!file.getParentFile().exists()) {
//            file.getParentFile().mkdirs();
//        }
//        intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
//        startActivityForResult(intent, requestCode);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.btn_activity_identification_shop:
                if (TextUtils.isEmpty(url1)) {
                    UIUtils.showToast("请上传身份证正面照");
                    return;
                }
                if (TextUtils.isEmpty(url2)) {
                    UIUtils.showToast("请上传身份证背面照");
                    return;
                }
                if (TextUtils.isEmpty(url3)) {
                    UIUtils.showToast("请上传手持身份证正面照");
                    return;
                }
                if (TextUtils.isEmpty(url1)) {
                    UIUtils.showToast("请上传手持结算卡正面照");
                    return;
                }
                ApiManager.getApi().updateInfoPic(
                        "HSS001039",
                        url1,
                        url2,
                        url3,
                        url4
                ).enqueue(new NetCallBack<String>() {
                    @Override
                    protected void onSuccess(Call<String> call, Response<String> response) {
                        ActivityUtils.startActivityAndFinish(UpdatePicActivity.this, WitePassActivity.class);
                    }
                });

                break;
            case R.id.iv_activity_identification_shop_step2_door:
                if (PermissionUtils.hasCameraPermission()) {
                    if (PermissionUtils.hasWriteSDCardPermission()) {
                        takePicture(0);
                    } else {
                        ActivityCompat.requestPermissions(this,
                                new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                                MY_PERMISSIONS_REQUEST_CALL_WRITE_SDCARD);
                    }
                } else {
                    ActivityCompat.requestPermissions(this,
                            new String[]{Manifest.permission.CAMERA},
                            MY_PERMISSIONS_REQUEST_CALL_CAMERA);
                }

                break;
            case R.id.iv_activity_identification_shop_step2_counter:
                if (PermissionUtils.hasCameraPermission()) {
                    if (PermissionUtils.hasWriteSDCardPermission()) {
                        takePicture(1);
                    } else {
                        ActivityCompat.requestPermissions(this,
                                new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                                MY_PERMISSIONS_REQUEST_CALL_WRITE_SDCARD);
                    }
                } else {
                    ActivityCompat.requestPermissions(this,
                            new String[]{Manifest.permission.CAMERA},
                            MY_PERMISSIONS_REQUEST_CALL_CAMERA);
                }

                break;
            case R.id.iv_activity_identification_shop_step2_indoor:
                if (PermissionUtils.hasCameraPermission()) {
                    if (PermissionUtils.hasWriteSDCardPermission()) {
                        takePicture(2);
                    } else {
                        ActivityCompat.requestPermissions(this,
                                new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                                MY_PERMISSIONS_REQUEST_CALL_WRITE_SDCARD);
                    }
                } else {
                    ActivityCompat.requestPermissions(this,
                            new String[]{Manifest.permission.CAMERA},
                            MY_PERMISSIONS_REQUEST_CALL_CAMERA);
                }

                break;
            case R.id.iv_activity_identification_shop_step2_bankcard:
                if (PermissionUtils.hasCameraPermission()) {
                    if (PermissionUtils.hasWriteSDCardPermission()) {
                        takePicture(3);
                    } else {
                        ActivityCompat.requestPermissions(this,
                                new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                                MY_PERMISSIONS_REQUEST_CALL_WRITE_SDCARD);
                    }
                } else {
                    ActivityCompat.requestPermissions(this,
                            new String[]{Manifest.permission.CAMERA},
                            MY_PERMISSIONS_REQUEST_CALL_CAMERA);
                }

                break;
        }
    }

    private void doNetWork(String path, final int type) {
        showLoadingDialog();
        HashMap<String, Object> requestDataMap = new HashMap<>();
        requestDataMap.put("fileA", "pic");
        File fileA = new File(path);
        String requestData = JSON.toJSONString(requestDataMap, false);
        String token = SharedPreferencesUtils.getString(ConsultInterceptor.ACCESS_TOKEN, "");
        LogUtils.error(requestData);
        Map<String, RequestBody> params = RequestUtils.createPartMap(
                new RequestParam("serviceCode", "HSS001037"),
                new RequestParam("accessToken", token),
                new RequestParam("requestData", requestData),
                new RequestParam(HttpConfig.GlobalParam.APP_TYPE, "android"),
                new RequestParam(HttpConfig.GlobalParam.V, "v1.0.0"),
                new RequestParam(HttpConfig.GlobalParam.TIME_STAMP, DateUtils.getCurrentTime()),
                new RequestParam(HttpConfig.GlobalParam.DEVICE_ID, DeviceUtils.getDeviceId() + ""),
                new RequestParam("fileA", fileA)
        );
        Retrofit.Builder retrofitBuilder = new Retrofit.Builder();
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        retrofitBuilder.client(builder.build())
                .baseUrl(HttpConfig.BASE_URL) //这里的baseUrl不用设置
                .addConverterFactory(FastJsonConverterFactory.create())
                .build()
                .create(FileApi.class).uploadFileAndForm(params).enqueue(new NetCallBack<BaseGetBean>() {
            @Override
            protected void onSuccess(Call<BaseGetBean> call, Response<BaseGetBean> response) {
                UIUtils.showToast("图片上传成功");
                BaseGetBean baseGetBean = new BaseGetBean();
                if (response != null) {
                    try {
                        baseGetBean = response.body();
                        UIUtils.showToast(baseGetBean.resultMessage);
                        Gson gson = new Gson();
                        AuStepBean auStepBean = gson.fromJson(baseGetBean.encryptDataResult, AuStepBean.class);
                        switch (type) {
                            case 1:
                                url1 = auStepBean.url;
                                break;
                            case 2:
                                url2 = auStepBean.url;
                                break;
                            case 3:
                                url3 = auStepBean.url;
                                break;
                            case 4:
                                url4 = auStepBean.url;
                                break;
                        }
                    } catch (JsonSyntaxException e) {
                        e.printStackTrace();
                    }
                }
            }

            @Override
            protected boolean isNullNeedCallback() {
                return true;
            }

            @Override
            protected void hiddenProgress() {
                hideLodingDialog();
            }
        });
    }

    @Override
    protected void handleMessage(BaseActivity context, Message msg) {
        switch (msg.what) {
            case 300: //图片
                int type = (int) msg.obj;
                String path = "";
                ImageView distView = null;
                switch (type) {
                    case 0:
                        path = TAKE_PHOTO_PATH_DOOR;
                        distView = mDoorView;
                        hasDoorImage = true;
                        Glide.with(this)//
                                .load(Environment.getExternalStorageDirectory() + "/" + path)//
                                .skipMemoryCache(true)//
                                .diskCacheStrategy(DiskCacheStrategy.NONE)
                                .into(distView);
                        doNetWork(Environment.getExternalStorageDirectory() + "/" + path, 1);
                        break;
                    case 1:
                        path = TAKE_PHOTO_PATH_COUNTER;
                        distView = mCounterView;
                        hasCounterImage = true;
                        Glide.with(this)//
                                .load(Environment.getExternalStorageDirectory() + "/" + path)//
                                .skipMemoryCache(true)//
                                .diskCacheStrategy(DiskCacheStrategy.NONE)
                                .into(distView);
                        doNetWork(Environment.getExternalStorageDirectory() + "/" + path, 2);
                        break;
                    case 2:
                        path = TAKE_PHOTO_PATH_INDOOR;
                        distView = mIndoorView;
                        hasIndoorImage = true;
                        Glide.with(this)//
                                .load(Environment.getExternalStorageDirectory() + "/" + path)//
                                .skipMemoryCache(true)//
                                .diskCacheStrategy(DiskCacheStrategy.NONE)
                                .into(distView);
                        doNetWork(Environment.getExternalStorageDirectory() + "/" + path, 3);
                        break;
                    case 3:
                        path = picturePath;
                        distView = mDoorView;
                        hasDoorImage = true;
                        Glide.with(this)//
                                .load(path)//
                                .skipMemoryCache(true)//
                                .diskCacheStrategy(DiskCacheStrategy.NONE)
                                .into(distView);
                        doNetWork(path, 1);
                        break;
                    case 4:
                        path = picturePath1;
                        distView = mCounterView;
                        hasCounterImage = true;
                        Glide.with(this)//
                                .load(path)//
                                .skipMemoryCache(true)//
                                .diskCacheStrategy(DiskCacheStrategy.NONE)
                                .into(distView);
                        doNetWork(path, 2);
                        break;
                    case 5:
                        path = picturePath2;
                        distView = mIndoorView;
                        hasIndoorImage = true;
                        Glide.with(this)//
                                .load(path)//
                                .skipMemoryCache(true)//
                                .diskCacheStrategy(DiskCacheStrategy.NONE)
                                .into(distView);
                        doNetWork(path, 3);
                        break;
                    case 6:
                        path = TAKE_PHOTO_PATH_BANKCARD;
                        distView = mBankCardView;
                        hasIndoorImage = true;
                        Glide.with(this)//
                                .load(Environment.getExternalStorageDirectory() + "/" + path)//
                                .skipMemoryCache(true)//
                                .diskCacheStrategy(DiskCacheStrategy.NONE)
                                .into(distView);
                        doNetWork(Environment.getExternalStorageDirectory() + "/" + path, 4);
                        break;
                    case 7:
                        path = picturePath3;
                        distView = mBankCardView;
                        hasIndoorImage = true;
                        Glide.with(this)//
                                .load(path)//
                                .skipMemoryCache(true)//
                                .diskCacheStrategy(DiskCacheStrategy.NONE)
                                .into(distView);
                        doNetWork(path, 4);
                        break;
                }

                hideLodingDialog();
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        String filePath = null;
        if (resultCode == RESULT_OK) {
            switch (requestCode) {
                case REQUEST_CODE_TAKE_PHOTO_DOOR:
                    filePath = Environment.getExternalStorageDirectory() + "/" + TAKE_PHOTO_PATH_DOOR;
                    showLoadingDialog();
                    new CompressPhotoThread(mHandler, filePath, REQUEST_CODE_TAKE_PHOTO_DOOR).start();
                    break;
                case REQUEST_CODE_TAKE_PHOTO_DOOR_PHOTO:
                    Uri selectedImage = data.getData();
                    String[] filePathColumn = {MediaStore.Images.Media.DATA};
                    Cursor cursor = getContentResolver().query(selectedImage,
                            filePathColumn, null, null, null);
                    cursor.moveToFirst();
                    int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                    picturePath = cursor.getString(columnIndex);
                    cursor.close();
                    new CompressPhotoThread(mHandler, picturePath, 3).start();
                    showLoadingDialog();
                    break;
                case REQUEST_CODE_TAKE_PHOTO_COUNTER:
                    filePath = Environment.getExternalStorageDirectory() + "/" + TAKE_PHOTO_PATH_COUNTER;
                    showLoadingDialog();
                    new CompressPhotoThread(mHandler, filePath, REQUEST_CODE_TAKE_PHOTO_COUNTER).start();
                    break;
                case REQUEST_CODE_TAKE_PHOTO_COUNTER_PHOTO:
                    Uri selectedImage1 = data.getData();
                    String[] filePathColumn1 = {MediaStore.Images.Media.DATA};
                    Cursor cursor1 = getContentResolver().query(selectedImage1,
                            filePathColumn1, null, null, null);
                    cursor1.moveToFirst();
                    int columnIndex1 = cursor1.getColumnIndex(filePathColumn1[0]);
                    picturePath1 = cursor1.getString(columnIndex1);
                    cursor1.close();
                    new CompressPhotoThread(mHandler, picturePath1, 4).start();
                    showLoadingDialog();
                    break;
                case REQUEST_CODE_TAKE_PHOTO_INDOOR:
                    filePath = Environment.getExternalStorageDirectory() + "/" + TAKE_PHOTO_PATH_INDOOR;
                    showLoadingDialog();
                    new CompressPhotoThread(mHandler, filePath, REQUEST_CODE_TAKE_PHOTO_INDOOR).start();
                    break;
                case REQUEST_CODE_TAKE_PHOTO_INDOOR_PHOTO:
                    Uri selectedImage2 = data.getData();
                    String[] filePathColumn2 = {MediaStore.Images.Media.DATA};
                    Cursor cursor2 = getContentResolver().query(selectedImage2,
                            filePathColumn2, null, null, null);
                    cursor2.moveToFirst();
                    int columnIndex2 = cursor2.getColumnIndex(filePathColumn2[0]);
                    picturePath2 = cursor2.getString(columnIndex2);
                    cursor2.close();
                    new CompressPhotoThread(mHandler, picturePath2, 5).start();
                    showLoadingDialog();
                    break;
                case REQUEST_CODE_TAKE_PHOTO_BANKCARD:
                    filePath = Environment.getExternalStorageDirectory() + "/" + TAKE_PHOTO_PATH_BANKCARD;
                    showLoadingDialog();
                    new CompressPhotoThread(mHandler, filePath, 6).start();
                    break;
                case REQUEST_CODE_TAKE_PHOTO_BANKCARD_PHOTO:
                    Uri selectedImage3 = data.getData();
                    String[] filePathColumn3 = {MediaStore.Images.Media.DATA};
                    Cursor cursor3 = getContentResolver().query(selectedImage3,
                            filePathColumn3, null, null, null);
                    cursor3.moveToFirst();
                    int columnIndex3 = cursor3.getColumnIndex(filePathColumn3[0]);
                    picturePath3 = cursor3.getString(columnIndex3);
                    cursor3.close();
                    new CompressPhotoThread(mHandler, picturePath3, 7).start();
                    showLoadingDialog();
                    break;
            }
        }
    }

}
